package com.fourpigeon.dao;

import com.fourpigeon.domain.Follow;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
//
/**
 * 关注
 * 数据库操作
 */
@Mapper
@Repository
public interface FollowDao {
    /**
     * 获取userId的所有关注者
     * @param userId 用户id
     * @return Follow类型的List
     */
    @Select("select * from tb_follow where userId = #{userId}")
    public List<Follow> getByUserId(Long userId);

    /**
     * 查询userId是否有关注tarId
     * @param userId 用户id
     * @param tarId 目标用户id
     * @return Follow对象
     */
    @Select("select * from tb_follow where userId = #{userId} and followUserId = #{tarId}")
    public Follow isFollow(Long userId,Long tarId);

    @Select("select * from tb_follow where followUserId = #{tarId}")
    public List<Follow> getFollowers(Long tarId);

    @Insert("insert into tb_follow values(#{id},#{userId},#{followUserId},#{followUserIcon},#{createTime})")
    public boolean save(Follow follow);

    /**
     * 按照userId和followId删除数据
     * @param userId 用户id
     * @param followId 被关注的用户id
     * @return 成功与否
     */
    @Delete("delete from tb_follow where userId = #{userId} and followUserId = #{followId}")
    public boolean deleteByUserIdAndFollowId(Long userId,Long followId);
}
